package com.systemsjr.jrbbf.expense;

import java.util.Vector;

import net.rim.device.api.collection.util.BasicFilteredList;
import net.rim.device.api.command.Command;
import net.rim.device.api.command.CommandHandler;
import net.rim.device.api.command.ReadOnlyCommandMetadata;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.component.AutoCompleteField;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.util.StringProvider;

import com.systemsjr.jrbbf.common.ExpenseManagerScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class ExpenseScreen extends ExpenseManagerScreen
{
	private Expense expense;
	private boolean newExpense;
    private ManageExpense sqlManager;
    private EditField amountField;
    /**
     * Creates a new ExpenseView object
     */
    public ExpenseScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("Expense Manager");
    }
    
    public ExpenseScreen(ManageExpense sqlManager)
    {        
        // Set the displayed title of the screen       
        setTitle("Expense Manager");
        this.sqlManager = sqlManager;
        
        //Create an autocomplete field
        BasicFilteredList filterList = new BasicFilteredList();        
        Vector exp = new ManageExpenseType(ExpenseManagerScreen.db).getAll();
        ExpenseType[] expenseTypes = new ExpenseType[exp.size()];
        for(int i = 0; i < exp.size(); i++){
        	expenseTypes[i] = (ExpenseType) exp.elementAt(i);
        }
        filterList.addDataSet(1, expenseTypes, "expenseTypes", BasicFilteredList.COMPARISON_IGNORE_CASE);
        AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
        //autoCompleteField.set
        add(autoCompleteField);
    }
    
    protected boolean onSave(){
    	
    	return true;
    }
	protected void doReload() {
		// TODO Auto-generated method stub
		
	}
	
	/**
     * @see MainScreen#makeMenu(Menu, int)
     */
    protected void makeMenu(Menu menu, int instance)
    {
        MenuItem save = new MenuItem(new StringProvider("Save"), 0x230010, 0);
        save.setCommand(new Command(new CommandHandler() 
        {
            /**
             * @see net.rim.device.api.command.CommandHandler#execute(ReadOnlyCommandMetadata, Object)
             */
            public void execute(ReadOnlyCommandMetadata metadata, Object context) 
            {
                onSave();             
            }
        }));
        
        menu.add(save);
        menu.add(exipApp());
        menu.add(viewExpenses());
    }
}
